package com.yy.utils;

import java.io.Serializable;

/**
 * 通用返回结果
 * @Author: lyy
 * Date: 2021/11/23 15:03
 */
public class Result<T> implements Serializable {
	private static final Integer OK = 200;
	private static final Integer ERROR = 500;
	private static final String SUCCESS = "success";

	private Integer code;
	private T data;
	private String msg;

	public Result() {
	}
	
	public Result(Integer code, T data, String msg) {
		this.code = code;
		this.data = data;
		this.msg = msg;
	}

	public static <T> Result ok(){
		return Result.ok(OK, null, SUCCESS);
	}
	public static <T> Result ok(T data){
		return Result.ok(OK, data, null);
	}

	public static <T> Result ok(Integer code, T data, String msg){
		return new Result(code, data, msg);
	}


	public static <T> Result error(String msg){
		return Result.error(ERROR, null, msg);
	}

	public static <T> Result error(Integer code, String msg){
		return Result.error(code, null, msg);
	}

	public static <T> Result error(Integer code, T data, String msg){
		return new Result(code, data, msg);
	}

	public Integer getCode() {
		return code;
	}

	public void setCode(Integer code) {
		this.code = code;
	}

	public T getData() {
		return data;
	}

	public void setData(T data) {
		this.data = data;
	}

	public String getMsg() {
		return msg;
	}

	public void setMsg(String msg) {
		this.msg = msg;
	}
}
